﻿package net.wangit.dev;

import java.util.List;

import net.wangit.MapList;
import net.wangit.framework.config.BeanFactory;
import net.wangit.util.XMLUtil;

import org.dom4j.Document;
import org.dom4j.Element;


public class BeanEnumerationHelper {

	public BeanEnumerationHelper() {
	}

	public static MapList getEnumeration(String region) {
		MapList result = new MapList();
		Document document = XMLUtil.parseByPath(BeanFactory.getPath());
		Element root = document.getRootElement();
		List<?> list = root.element(region).elements("bean");
		for (int i = 0; i < list.size(); i++) {
			Element element = (Element) list.get(i);
			String id = element.attributeValue("id");
			result.put(i, "value", id);
			result.put(i, "name", (new StringBuilder("$L{components:")).append(
					region).append(".").append(id).append("}").toString());
		}

		return result;
	}
}
